using System.Linq;
using UnityEngine;
using WorldGenerators.Scripts.Abstractions.Interfaces;
using WorldGenerators.Scripts.Abstractions.Enums;

namespace WorldGenerators.Scripts
{
    public class NewTile : MonoBehaviour, ITile
    {
        [field: SerializeField] [field: Range(0, 100)] public int Weight { get; private set; }
        [field: Space]
        [field: Header("Possible Tile Prefabs")]
        [field: SerializeField] public GameObject[] PossibleRightTilePrefabs { get; private set; }
        [field: SerializeField] public GameObject[] PossibleFrontTilePrefabs { get; private set; }
        [field: SerializeField] public GameObject[] PossibleLeftTilePrefabs { get; private set; }
        [field: SerializeField] public GameObject[] PossibleBackTilePrefabs { get; private set; }

        private void Awake()
        {
            PossibleRightTilePrefabs = PossibleRightTilePrefabs
                .OrderByDescending(tile => tile.GetComponent<ITile>().Weight)
                .ToArray();
            PossibleFrontTilePrefabs = PossibleFrontTilePrefabs
                .OrderByDescending(tile => tile.GetComponent<ITile>().Weight)
                .ToArray();
            PossibleLeftTilePrefabs = PossibleLeftTilePrefabs
                .OrderByDescending(tile => tile.GetComponent<ITile>().Weight)
                .ToArray();
            PossibleBackTilePrefabs = PossibleBackTilePrefabs
                .OrderByDescending(tile => tile.GetComponent<ITile>().Weight)
                .ToArray();
        }

        public void Rotate90()
        {

        }
    }
}
